public class Test1 {
    public static void main(String[] args) throws InterruptedException {
          Thread t1 = new Thread(()->{
              while (!Thread.currentThread().isInterrupted()){
                  try{
                      System.out.println("t1正在运行");
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                      break;             // 使用break让循环停止  ;
                  }
              }
              System.out.println("t1停止");
          }, "t1");
           t1.start();
        // 在t1运行5秒后,将t1的标志位置为true,
        System.out.println("5秒后t1停止");
        Thread.sleep(5000);
        System.out.println("将t1的 标志位 置为true");
        t1.interrupt();
    }
}
